import AccessTimeFilledIcon from '@mui/icons-material/AccessTimeFilled';
import AccountBalanceIcon from '@mui/icons-material/AccountBalance';
import BalanceIcon from '@mui/icons-material/Balance';
import BeenhereIcon from '@mui/icons-material/Beenhere';
// 动态生成并计算数量
export function generateMenuData(data) {
  // 统计数量的辅助函数
  const countOccurrences = (array, key) => {
    return array.reduce((acc, item) => {
      let value = item[key];
      // 检查 key 是否为 "publishedAt" 并且 value 是否是有效的日期字符串
      if (key === "publishedAt" && !isNaN(Date.parse(value))) {
        value = new Date(value).getFullYear(); // 获取年份
      }
      // 统计出现次数
      acc[value] = (acc[value] || 0) + 1;
      return acc;
    }, {});
  };

  // 生成菜单数据项
  const effectivenessLevelCount = countOccurrences(data, "effectivenessLevel");
  const publishDepartmentCount = countOccurrences(data, "publishDepartment");
  const isValidCount = countOccurrences(data, "isValid");
  const publishedAtCount = countOccurrences(data, "publishedAt");
  
 
  
  // 转换为菜单格式
  return [
    {
      index: "1",
      title: "effectivenessLevel",
      icon:BalanceIcon,
      items: Object.entries(effectivenessLevelCount).map(([key, count]) => ({
        label: key,
        count,
      })),
    },
    {
      index: "2",
      title: "publishDepartment",
      icon: AccountBalanceIcon,
      items: Object.entries(publishDepartmentCount).map(([key, count]) => ({
        label: key,
        count,
      })),
    },
    {
      index: "3",
      title: "isValid",
      icon: BeenhereIcon,
      items: Object.entries(isValidCount).map(([key, count]) => ({
        label: key ? "现行有效" : "无效",
        count,
      })),
    },
    {
      index: "4",
      title: "publishedAt",
      icon: AccessTimeFilledIcon,
      items: Object.entries(publishedAtCount).map(([key, count]) => ({
        label: key,
        count,
      })),
    },
  ];
}

//
 export const TRANSLATION_LEVEL = {
  1: "法律",
  2:"行政法规",
  3: "省、自治区、直辖市地方性法规",
  4: "市地方性法规"
};

export const CHINESE_SHOW_MODEL = {
  geography: "地域",
  publishedAt: "发布日期",
  isValid: "有效性",
  publishDepartment: "发布部门",
  effectivenessLevel: "效力级别",
  true: "全文",
  false: "标题"
};

export const VALID_MODEL = {
  1: "现行有效",
  0: "现行无效",
};

export const TABTEXTMODULE = {
  legislation: 0,
  judgment: 1,
  contract: 2,
};
